using System.Collections.Generic;

namespace Battle.TimelineLog
{
    /// <summary>
    /// 战斗中参与者状态
    /// </summary>
    public class FightStatus
    {
        private Dictionary<SeEnumSkillEffectstatus, int> statusDic = new Dictionary<SeEnumSkillEffectstatus, int>();

        public FightStatus()
        {
            statusDic.Clear();
        }

        /// <summary>
        /// 加状态
        /// </summary>
        /// <param name="status"></param>
        /// <param name="count"></param>
        public void AddStatus(SeEnumSkillEffectstatus status, int count = 1)
        {
            int temp = 1;
            if (statusDic.TryGetValue(status, out temp))
                statusDic[status] = temp + count;
            else
                statusDic.TryAdd(status, count);
        }

        /// <summary>
        /// 批量加状态
        /// </summary>
        /// <param name="statuses"></param>
        /// <param name="counts"></param>
        public void AddStatus(List<SeEnumSkillEffectstatus> statuses, List<int> counts = null)
        {
            for (int i = 0, n = statuses.Count; i < n; i++)
            {
                AddStatus(statuses[i], counts == null ? 1 : counts[i]);
            }
        }

        /// <summary>
        /// 减状态
        /// </summary>
        /// <param name="status"></param>
        /// <param name="count"></param>
        public void RemoveStatus(SeEnumSkillEffectstatus status, int count = 1)
        {
            int temp = 1;
            if (statusDic.TryGetValue(status, out temp))
            {
                int n = temp - count;
                statusDic[status] = n > 0 ? n : 0;
            }
        }

        /// <summary>
        /// 批量减状态
        /// </summary>
        /// <param name="statuses"></param>
        /// <param name="counts"></param>
        public void RemoveStatus(List<SeEnumSkillEffectstatus> statuses, List<int> counts = null)
        {
            for (int i = 0, n = statuses.Count; i < n; i++)
            {
                RemoveStatus(statuses[i], counts == null ? 1 : counts[i]);
            }
        }

        /// <summary>
        /// 清除某状态
        /// </summary>
        /// <param name="status"></param>
        public void ClearStatus(SeEnumSkillEffectstatus status)
        {
            statusDic.Remove(status);
        }

        public bool HasStatus(SeEnumSkillEffectstatus status)
        {
            int cnt = 0;
            statusDic.TryGetValue(status, out cnt);
            return cnt > 0;
        }

        public bool HasOneOfStatus(List<SeEnumSkillEffectstatus> statuses)
        {
            for (int i = 0, n = statuses.Count; i < n; i++)
            {
                if (HasStatus(statuses[i]))
                {
                    return true;
                }
            }
            return false;
        }

        public bool HasAllStatus(List<SeEnumSkillEffectstatus> statuses)
        {
            for (int i = 0, n = statuses.Count; i < n; i++)
            {
                if (!HasStatus(statuses[i]))
                {
                    return false;
                }
            }
            return true;
        }


    }
}